package com.xxxx.rpc.service.impl;

//import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.sms.v20190711.SmsClient;
//import com.tencentcloudapi.sms.v20190711.models.SendSmsRequest;
//import com.tencentcloudapi.sms.v20190711.models.SendSmsResponse;
import com.tencentcloudapi.sms.v20190711.models.SendSmsRequest;
import com.tencentcloudapi.sms.v20190711.models.SendSmsResponse;
import com.xxxx.common.result.RespBean;
import com.xxxx.rpc.service.SendMessageService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.stereotype.Component;

/**
 * 发送短信实现类
 */

@Service(interfaceClass = SendMessageService.class)
@Component
public class SendMessage implements SendMessageService {

    @Override
    public RespBean SendMessage(String email) {
        try{
            //实例化一个认证对象，获取签名串
            Credential cred = new Credential("AKIDxg9PXY2G0Z0A5kkLN9mE1YonWJrG3FqC", "HvJT5RWP2PUTCo9EFzShg6OgiSwpTqUy");
            //实例化httpProfile对象，调用短信发送接口的url
            HttpProfile httpProfile = new HttpProfile();
            httpProfile.setEndpoint("sms.tencentcloudapi.com");
            //实例化ClientProfile对象
            ClientProfile clientProfile = new ClientProfile();
            clientProfile.setHttpProfile(httpProfile);
            //实例化Sms客户端
            SmsClient client = new SmsClient(cred, "", clientProfile);

            SendSmsRequest req = new SendSmsRequest();
            String str = "86"+email;
            String[] phoneNumberSet1 = {str};
            //参数：电话号码
            req.setPhoneNumberSet(phoneNumberSet1);
            //参数：短信SdkAppId
            req.setSmsSdkAppid("1400456423");
            //参数：模板id
            req.setTemplateID("791387");
            //参数：签名内容
            req.setSign("java永远滴神");
            //发送请求
            SendSmsResponse resp = client.SendSms(req);

            if("ok".equalsIgnoreCase(resp.getSendStatusSet()[0].getCode())){
                return RespBean.success("短信发送成功！");
            }
            System.out.println(SendSmsResponse.toJsonString(resp));
        } catch (TencentCloudSDKException e) {
            System.out.println(e.toString());
        }
        return RespBean.error("短信发送失败！");
    }
}
